from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-01 14:02:42.570874
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 01, Dec, 2022
Time: 14:02:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1096
Nobs: 857.000 HQIC: -51.4176
Log likelihood: 11260.1 FPE: 3.86009e-23
AIC: -51.6088 Det(Omega_mle): 3.47738e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299240 0.050139 5.968 0.000
L1.Burgenland 0.109596 0.034468 3.180 0.001
L1.Kärnten -0.106061 0.018360 -5.777 0.000
L1.Niederösterreich 0.210722 0.072050 2.925 0.003
L1.Oberösterreich 0.100316 0.068386 1.467 0.142
L1.Salzburg 0.251394 0.036539 6.880 0.000
L1.Steiermark 0.037148 0.047899 0.776 0.438
L1.Tirol 0.107613 0.038850 2.770 0.006
L1.Vorarlberg -0.059936 0.033479 -1.790 0.073
L1.Wien 0.054262 0.061139 0.888 0.375
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067464 0.103402 0.652 0.514
L1.Burgenland -0.030341 0.071083 -0.427 0.670
L1.Kärnten 0.047563 0.037865 1.256 0.209
L1.Niederösterreich -0.172068 0.148590 -1.158 0.247
L1.Oberösterreich 0.376073 0.141034 2.667 0.008
L1.Salzburg 0.288553 0.075354 3.829 0.000
L1.Steiermark 0.108504 0.098783 1.098 0.272
L1.Tirol 0.316648 0.080122 3.952 0.000
L1.Vorarlberg 0.023380 0.069044 0.339 0.735
L1.Wien -0.019405 0.126088 -0.154 0.878
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198108 0.025970 7.628 0.000
L1.Burgenland 0.092784 0.017853 5.197 0.000
L1.Kärnten -0.008735 0.009510 -0.919 0.358
L1.Niederösterreich 0.268255 0.037319 7.188 0.000
L1.Oberösterreich 0.115446 0.035421 3.259 0.001
L1.Salzburg 0.052379 0.018925 2.768 0.006
L1.Steiermark 0.016909 0.024810 0.682 0.496
L1.Tirol 0.098721 0.020123 4.906 0.000
L1.Vorarlberg 0.056048 0.017341 3.232 0.001
L1.Wien 0.111115 0.031667 3.509 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105181 0.026636 3.949 0.000
L1.Burgenland 0.047255 0.018311 2.581 0.010
L1.Kärnten -0.017368 0.009754 -1.781 0.075
L1.Niederösterreich 0.196975 0.038277 5.146 0.000
L1.Oberösterreich 0.280226 0.036330 7.713 0.000
L1.Salzburg 0.120196 0.019411 6.192 0.000
L1.Steiermark 0.101238 0.025446 3.978 0.000
L1.Tirol 0.123782 0.020639 5.997 0.000
L1.Vorarlberg 0.068815 0.017786 3.869 0.000
L1.Wien -0.027150 0.032480 -0.836 0.403
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130685 0.048210 2.711 0.007
L1.Burgenland -0.048960 0.033142 -1.477 0.140
L1.Kärnten -0.039561 0.017654 -2.241 0.025
L1.Niederösterreich 0.166562 0.069279 2.404 0.016
L1.Oberösterreich 0.140085 0.065756 2.130 0.033
L1.Salzburg 0.284542 0.035133 8.099 0.000
L1.Steiermark 0.033505 0.046057 0.727 0.467
L1.Tirol 0.163189 0.037356 4.368 0.000
L1.Vorarlberg 0.103888 0.032191 3.227 0.001
L1.Wien 0.067764 0.058787 1.153 0.249
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058833 0.038180 1.541 0.123
L1.Burgenland 0.042778 0.026246 1.630 0.103
L1.Kärnten 0.049881 0.013981 3.568 0.000
L1.Niederösterreich 0.227481 0.054864 4.146 0.000
L1.Oberösterreich 0.272277 0.052075 5.229 0.000
L1.Salzburg 0.057978 0.027823 2.084 0.037
L1.Steiermark -0.007039 0.036474 -0.193 0.847
L1.Tirol 0.156209 0.029584 5.280 0.000
L1.Vorarlberg 0.068313 0.025493 2.680 0.007
L1.Wien 0.073886 0.046556 1.587 0.113
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185201 0.045683 4.054 0.000
L1.Burgenland -0.004391 0.031404 -0.140 0.889
L1.Kärnten -0.061068 0.016729 -3.651 0.000
L1.Niederösterreich -0.087668 0.065646 -1.335 0.182
L1.Oberösterreich 0.191781 0.062308 3.078 0.002
L1.Salzburg 0.059949 0.033291 1.801 0.072
L1.Steiermark 0.225555 0.043642 5.168 0.000
L1.Tirol 0.495292 0.035397 13.992 0.000
L1.Vorarlberg 0.047963 0.030503 1.572 0.116
L1.Wien -0.050533 0.055705 -0.907 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158576 0.052058 3.046 0.002
L1.Burgenland -0.008899 0.035787 -0.249 0.804
L1.Kärnten 0.064745 0.019063 3.396 0.001
L1.Niederösterreich 0.202829 0.074808 2.711 0.007
L1.Oberösterreich -0.067389 0.071004 -0.949 0.343
L1.Salzburg 0.222402 0.037938 5.862 0.000
L1.Steiermark 0.113718 0.049733 2.287 0.022
L1.Tirol 0.084367 0.040338 2.092 0.036
L1.Vorarlberg 0.122261 0.034761 3.517 0.000
L1.Wien 0.109258 0.063480 1.721 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357063 0.030731 11.619 0.000
L1.Burgenland 0.009143 0.021126 0.433 0.665
L1.Kärnten -0.024784 0.011254 -2.202 0.028
L1.Niederösterreich 0.227540 0.044161 5.152 0.000
L1.Oberösterreich 0.157195 0.041916 3.750 0.000
L1.Salzburg 0.052723 0.022395 2.354 0.019
L1.Steiermark -0.017093 0.029359 -0.582 0.560
L1.Tirol 0.117634 0.023812 4.940 0.000
L1.Vorarlberg 0.072033 0.020520 3.510 0.000
L1.Wien 0.049963 0.037474 1.333 0.182
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043690 0.161229 0.191841 0.165552 0.132365 0.124557 0.069972 0.231087
Kärnten 0.043690 1.000000 0.002031 0.131823 0.044940 0.098878 0.427430 -0.050706 0.101792
Niederösterreich 0.161229 0.002031 1.000000 0.344437 0.166957 0.311003 0.127825 0.192267 0.341725
Oberösterreich 0.191841 0.131823 0.344437 1.000000 0.235082 0.339877 0.177173 0.179248 0.274299
Salzburg 0.165552 0.044940 0.166957 0.235082 1.000000 0.153180 0.145187 0.152929 0.141444
Steiermark 0.132365 0.098878 0.311003 0.339877 0.153180 1.000000 0.163430 0.148248 0.092877
Tirol 0.124557 0.427430 0.127825 0.177173 0.145187 0.163430 1.000000 0.122260 0.164104
Vorarlberg 0.069972 -0.050706 0.192267 0.179248 0.152929 0.148248 0.122260 1.000000 0.020242
Wien 0.231087 0.101792 0.341725 0.274299 0.141444 0.092877 0.164104 0.020242 1.000000